﻿using ConsoleStudy;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace PicRec
{
    /// <summary>
    /// App.xaml 的交互逻辑
    /// </summary>
    public partial class App : Application
    {
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            bool isactive = CheckRegister();
            if (!isactive)
            {
                WinActive w = new WinActive();
                w.Show();
            }
            else
            {
                MainWindow m = new PicRec.MainWindow();
                m.Show();
            }
            
        }

        /// <summary>
        /// 检查软件是否激活
        /// </summary>
        /// <returns></returns>
        private static bool CheckRegister()
        {
            bool result = false;
            string licencePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "licence.fly");
            if (File.Exists(licencePath))
            {
                try
                {
                    StreamReader sr = new StreamReader(licencePath, Encoding.Unicode);
                    string code = FlyPC.GenerateMacCode();
                    string line = sr.ReadToEnd();
                    string key = FlyPC.Md5(code);
                    if (line == key)
                    {
                        result = true;
                    }
                    //清空缓冲区、关闭流
                    sr.Close();
                }
                catch
                {
                    result = false;
                }
            }
            return result;
        }

    }
}
